package sistkaraoke.servlet.local;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import sistkaraoke.excepcion.DAOExcepcion;
import sistkaraoke.negocio.GestionLocal;
import sistkaraoke.negocio.IGestionLocal;

/**
 * Servlet implementation class ActualizarLocalServlet
 */
@WebServlet("/ActualizarLocalServlet")
public class ActualizarLocalServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ActualizarLocalServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		
		String nombre = request.getParameter("txtNombre");
		String direccion = request.getParameter("txtDireccion");
		String telefono = request.getParameter("txtTelefono");
		String correo = request.getParameter("txtCorreo");
		String descripcion = request.getParameter("txtDescripcion");
		//int idadmin = request.getParameter("intIdAdmin") !=  "0" ? 
			//Integer.parseInt(request.getParameter("intIdAdmin").trim()) :0;
		int idlocal = Integer.parseInt(request.getParameter("idlocal"));
				
		IGestionLocal negocio = new GestionLocal();
		
		try {
			negocio.actualizar(idlocal, nombre, direccion, telefono, correo, descripcion);
			response.sendRedirect(request.getContextPath()	+ "/ListarLocalServlet");
		} catch (DAOExcepcion e) {
			System.out.println(e.getMessage());
			RequestDispatcher rd = request.getRequestDispatcher("error.jsp");
			rd.forward(request, response);
		}
	}

}
